<?php


abstract class BaseGenrFundacion extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $genr_fundacion_id;


	
	protected $genfun_nombre;


	
	protected $genfun_direccion;


	
	protected $genfun_telefono;


	
	protected $genfun_ruc;


	
	protected $genfun_fax;


	
	protected $genfun_replegal;


	
	protected $genfun_estado;

	
	protected $collFunmNinos;

	
	protected $lastFunmNinoCriteria = null;

	
	protected $collFunrParams;

	
	protected $lastFunrParamCriteria = null;

	
	protected $collFunrSpoxfuns;

	
	protected $lastFunrSpoxfunCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getGenrFundacionId()
	{

		return $this->genr_fundacion_id;
	}

	
	public function getGenfunNombre()
	{

		return $this->genfun_nombre;
	}

	
	public function getGenfunDireccion()
	{

		return $this->genfun_direccion;
	}

	
	public function getGenfunTelefono()
	{

		return $this->genfun_telefono;
	}

	
	public function getGenfunRuc()
	{

		return $this->genfun_ruc;
	}

	
	public function getGenfunFax()
	{

		return $this->genfun_fax;
	}

	
	public function getGenfunReplegal()
	{

		return $this->genfun_replegal;
	}

	
	public function getGenfunEstado()
	{

		return $this->genfun_estado;
	}

	
	public function setGenrFundacionId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->genr_fundacion_id !== $v) {
			$this->genr_fundacion_id = $v;
			$this->modifiedColumns[] = GenrFundacionPeer::GENR_FUNDACION_ID;
		}

	} 
	
	public function setGenfunNombre($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->genfun_nombre !== $v) {
			$this->genfun_nombre = $v;
			$this->modifiedColumns[] = GenrFundacionPeer::GENFUN_NOMBRE;
		}

	} 
	
	public function setGenfunDireccion($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->genfun_direccion !== $v) {
			$this->genfun_direccion = $v;
			$this->modifiedColumns[] = GenrFundacionPeer::GENFUN_DIRECCION;
		}

	} 
	
	public function setGenfunTelefono($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->genfun_telefono !== $v) {
			$this->genfun_telefono = $v;
			$this->modifiedColumns[] = GenrFundacionPeer::GENFUN_TELEFONO;
		}

	} 
	
	public function setGenfunRuc($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->genfun_ruc !== $v) {
			$this->genfun_ruc = $v;
			$this->modifiedColumns[] = GenrFundacionPeer::GENFUN_RUC;
		}

	} 
	
	public function setGenfunFax($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->genfun_fax !== $v) {
			$this->genfun_fax = $v;
			$this->modifiedColumns[] = GenrFundacionPeer::GENFUN_FAX;
		}

	} 
	
	public function setGenfunReplegal($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->genfun_replegal !== $v) {
			$this->genfun_replegal = $v;
			$this->modifiedColumns[] = GenrFundacionPeer::GENFUN_REPLEGAL;
		}

	} 
	
	public function setGenfunEstado($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->genfun_estado !== $v) {
			$this->genfun_estado = $v;
			$this->modifiedColumns[] = GenrFundacionPeer::GENFUN_ESTADO;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->genr_fundacion_id = $rs->getInt($startcol + 0);

			$this->genfun_nombre = $rs->getString($startcol + 1);

			$this->genfun_direccion = $rs->getString($startcol + 2);

			$this->genfun_telefono = $rs->getString($startcol + 3);

			$this->genfun_ruc = $rs->getString($startcol + 4);

			$this->genfun_fax = $rs->getString($startcol + 5);

			$this->genfun_replegal = $rs->getString($startcol + 6);

			$this->genfun_estado = $rs->getString($startcol + 7);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 8; 
		} catch (Exception $e) {
			throw new PropelException("Error populating GenrFundacion object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(GenrFundacionPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			GenrFundacionPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(GenrFundacionPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = GenrFundacionPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setGenrFundacionId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += GenrFundacionPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collFunmNinos !== null) {
				foreach($this->collFunmNinos as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collFunrParams !== null) {
				foreach($this->collFunrParams as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collFunrSpoxfuns !== null) {
				foreach($this->collFunrSpoxfuns as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = GenrFundacionPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collFunmNinos !== null) {
					foreach($this->collFunmNinos as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collFunrParams !== null) {
					foreach($this->collFunrParams as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collFunrSpoxfuns !== null) {
					foreach($this->collFunrSpoxfuns as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = GenrFundacionPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getGenrFundacionId();
				break;
			case 1:
				return $this->getGenfunNombre();
				break;
			case 2:
				return $this->getGenfunDireccion();
				break;
			case 3:
				return $this->getGenfunTelefono();
				break;
			case 4:
				return $this->getGenfunRuc();
				break;
			case 5:
				return $this->getGenfunFax();
				break;
			case 6:
				return $this->getGenfunReplegal();
				break;
			case 7:
				return $this->getGenfunEstado();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = GenrFundacionPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getGenrFundacionId(),
			$keys[1] => $this->getGenfunNombre(),
			$keys[2] => $this->getGenfunDireccion(),
			$keys[3] => $this->getGenfunTelefono(),
			$keys[4] => $this->getGenfunRuc(),
			$keys[5] => $this->getGenfunFax(),
			$keys[6] => $this->getGenfunReplegal(),
			$keys[7] => $this->getGenfunEstado(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = GenrFundacionPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setGenrFundacionId($value);
				break;
			case 1:
				$this->setGenfunNombre($value);
				break;
			case 2:
				$this->setGenfunDireccion($value);
				break;
			case 3:
				$this->setGenfunTelefono($value);
				break;
			case 4:
				$this->setGenfunRuc($value);
				break;
			case 5:
				$this->setGenfunFax($value);
				break;
			case 6:
				$this->setGenfunReplegal($value);
				break;
			case 7:
				$this->setGenfunEstado($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = GenrFundacionPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setGenrFundacionId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setGenfunNombre($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setGenfunDireccion($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setGenfunTelefono($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setGenfunRuc($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setGenfunFax($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setGenfunReplegal($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setGenfunEstado($arr[$keys[7]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(GenrFundacionPeer::DATABASE_NAME);

		if ($this->isColumnModified(GenrFundacionPeer::GENR_FUNDACION_ID)) $criteria->add(GenrFundacionPeer::GENR_FUNDACION_ID, $this->genr_fundacion_id);
		if ($this->isColumnModified(GenrFundacionPeer::GENFUN_NOMBRE)) $criteria->add(GenrFundacionPeer::GENFUN_NOMBRE, $this->genfun_nombre);
		if ($this->isColumnModified(GenrFundacionPeer::GENFUN_DIRECCION)) $criteria->add(GenrFundacionPeer::GENFUN_DIRECCION, $this->genfun_direccion);
		if ($this->isColumnModified(GenrFundacionPeer::GENFUN_TELEFONO)) $criteria->add(GenrFundacionPeer::GENFUN_TELEFONO, $this->genfun_telefono);
		if ($this->isColumnModified(GenrFundacionPeer::GENFUN_RUC)) $criteria->add(GenrFundacionPeer::GENFUN_RUC, $this->genfun_ruc);
		if ($this->isColumnModified(GenrFundacionPeer::GENFUN_FAX)) $criteria->add(GenrFundacionPeer::GENFUN_FAX, $this->genfun_fax);
		if ($this->isColumnModified(GenrFundacionPeer::GENFUN_REPLEGAL)) $criteria->add(GenrFundacionPeer::GENFUN_REPLEGAL, $this->genfun_replegal);
		if ($this->isColumnModified(GenrFundacionPeer::GENFUN_ESTADO)) $criteria->add(GenrFundacionPeer::GENFUN_ESTADO, $this->genfun_estado);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(GenrFundacionPeer::DATABASE_NAME);

		$criteria->add(GenrFundacionPeer::GENR_FUNDACION_ID, $this->genr_fundacion_id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getGenrFundacionId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setGenrFundacionId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setGenfunNombre($this->genfun_nombre);

		$copyObj->setGenfunDireccion($this->genfun_direccion);

		$copyObj->setGenfunTelefono($this->genfun_telefono);

		$copyObj->setGenfunRuc($this->genfun_ruc);

		$copyObj->setGenfunFax($this->genfun_fax);

		$copyObj->setGenfunReplegal($this->genfun_replegal);

		$copyObj->setGenfunEstado($this->genfun_estado);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getFunmNinos() as $relObj) {
				$copyObj->addFunmNino($relObj->copy($deepCopy));
			}

			foreach($this->getFunrParams() as $relObj) {
				$copyObj->addFunrParam($relObj->copy($deepCopy));
			}

			foreach($this->getFunrSpoxfuns() as $relObj) {
				$copyObj->addFunrSpoxfun($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setGenrFundacionId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new GenrFundacionPeer();
		}
		return self::$peer;
	}

	
	public function initFunmNinos()
	{
		if ($this->collFunmNinos === null) {
			$this->collFunmNinos = array();
		}
	}

	
	public function getFunmNinos($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseFunmNinoPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collFunmNinos === null) {
			if ($this->isNew()) {
			   $this->collFunmNinos = array();
			} else {

				$criteria->add(FunmNinoPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

				FunmNinoPeer::addSelectColumns($criteria);
				$this->collFunmNinos = FunmNinoPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(FunmNinoPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

				FunmNinoPeer::addSelectColumns($criteria);
				if (!isset($this->lastFunmNinoCriteria) || !$this->lastFunmNinoCriteria->equals($criteria)) {
					$this->collFunmNinos = FunmNinoPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastFunmNinoCriteria = $criteria;
		return $this->collFunmNinos;
	}

	
	public function countFunmNinos($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseFunmNinoPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(FunmNinoPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

		return FunmNinoPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addFunmNino(FunmNino $l)
	{
		$this->collFunmNinos[] = $l;
		$l->setGenrFundacion($this);
	}

	
	public function initFunrParams()
	{
		if ($this->collFunrParams === null) {
			$this->collFunrParams = array();
		}
	}

	
	public function getFunrParams($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseFunrParamPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collFunrParams === null) {
			if ($this->isNew()) {
			   $this->collFunrParams = array();
			} else {

				$criteria->add(FunrParamPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

				FunrParamPeer::addSelectColumns($criteria);
				$this->collFunrParams = FunrParamPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(FunrParamPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

				FunrParamPeer::addSelectColumns($criteria);
				if (!isset($this->lastFunrParamCriteria) || !$this->lastFunrParamCriteria->equals($criteria)) {
					$this->collFunrParams = FunrParamPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastFunrParamCriteria = $criteria;
		return $this->collFunrParams;
	}

	
	public function countFunrParams($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseFunrParamPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(FunrParamPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

		return FunrParamPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addFunrParam(FunrParam $l)
	{
		$this->collFunrParams[] = $l;
		$l->setGenrFundacion($this);
	}

	
	public function initFunrSpoxfuns()
	{
		if ($this->collFunrSpoxfuns === null) {
			$this->collFunrSpoxfuns = array();
		}
	}

	
	public function getFunrSpoxfuns($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseFunrSpoxfunPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collFunrSpoxfuns === null) {
			if ($this->isNew()) {
			   $this->collFunrSpoxfuns = array();
			} else {

				$criteria->add(FunrSpoxfunPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

				FunrSpoxfunPeer::addSelectColumns($criteria);
				$this->collFunrSpoxfuns = FunrSpoxfunPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(FunrSpoxfunPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

				FunrSpoxfunPeer::addSelectColumns($criteria);
				if (!isset($this->lastFunrSpoxfunCriteria) || !$this->lastFunrSpoxfunCriteria->equals($criteria)) {
					$this->collFunrSpoxfuns = FunrSpoxfunPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastFunrSpoxfunCriteria = $criteria;
		return $this->collFunrSpoxfuns;
	}

	
	public function countFunrSpoxfuns($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseFunrSpoxfunPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(FunrSpoxfunPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

		return FunrSpoxfunPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addFunrSpoxfun(FunrSpoxfun $l)
	{
		$this->collFunrSpoxfuns[] = $l;
		$l->setGenrFundacion($this);
	}


	
	public function getFunrSpoxfunsJoinFunmSponsor($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseFunrSpoxfunPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collFunrSpoxfuns === null) {
			if ($this->isNew()) {
				$this->collFunrSpoxfuns = array();
			} else {

				$criteria->add(FunrSpoxfunPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

				$this->collFunrSpoxfuns = FunrSpoxfunPeer::doSelectJoinFunmSponsor($criteria, $con);
			}
		} else {
									
			$criteria->add(FunrSpoxfunPeer::GENR_FUNDACION_ID, $this->getGenrFundacionId());

			if (!isset($this->lastFunrSpoxfunCriteria) || !$this->lastFunrSpoxfunCriteria->equals($criteria)) {
				$this->collFunrSpoxfuns = FunrSpoxfunPeer::doSelectJoinFunmSponsor($criteria, $con);
			}
		}
		$this->lastFunrSpoxfunCriteria = $criteria;

		return $this->collFunrSpoxfuns;
	}

} 